<template>
	<view class="login_bg">
		<image src="@/static/imgs/login_bottom.png" mode="widthFix" class="login_bottom"></image>
		<view style="background: #247BFF;height: 40vh;position: relative;z-index: -1;"></view>
		<view class="login_content">
			<view class="login_title">优果众采管理系统</view>
			<view class="login_box">
				<view class="login_name">登录</view>
				<view class="login_input">
					<image src="@/static/imgs/account.png" mode="widthFix"></image>
					<u--input  type="text" v-model="form.username" placeholder="请输入账号" />
				</view>
				<view class="login_input">
					<image src="@/static/imgs/password.png" mode="widthFix"></image>
					<u--input  type="password" v-model="form.password" placeholder="请输入密码" />
				</view>
				<view class="login_btn" @tap="login">登录</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {login} from '@/require/api.js';
	export default {
		data() {
			return {
				form: {
					password: '',
					username: '',
				}
			}
		},
		onLoad() {
		    let token=uni.getStorageSync('ygzcToken');
			if(token){
				this.$project.toTable('/pages/index/home');
			}
		},
		methods: {
			async login() {
				for (let i in this.form) {
					if (!this.form[i]) {
						return this.$project.toast('请填完所有信息后再提交');
					}
				}
				let {data,code,msg}= await login(this.form);
				if (code == 1) {
					uni.setStorageSync('ygzcToken', data.token);
					this.$project.toast(msg);
					setTimeout(() => {
						this.$project.toTable('/pages/index/home'); 
					}, 1000)

				} else {
					this.$project.toast(msg)
				}
			}
		},
		onShareAppMessage() {
		
		},
		onShareTimeline() {
		
		},
	}
</script>

<style lang="scss">
	.login_bg {
		background: url(../../static/imgs/login_top.png)no-repeat left top;
		background-size: 100% 520rpx;
		width: 100%;
		height: 100vh;

		.login_bottom {
			position: fixed;
			left: 0;
			bottom: 0;
			width: 286rpx;
		}

		.login_content {
			position: fixed;
			top: 280rpx;
			left: 50%;
			transform: translate(-50%, 0);
		}
	}

	.login_title {
		font-size: 40rpx;
		color: #FFFFFF;
		text-align: center;
		margin-bottom: 40rpx;
		font-weight: 600;
		line-height: 60rpx;
	}

	.login_box {
		width: 630rpx;

		padding-bottom: 30rpx;
		background: url(../../static/imgs/login_right.png)no-repeat right top;
		background-size: 115rpx 128rpx;
		background-color: #FFFFFF;
		box-shadow: 0px 2rpx 8rpx 0px rgba(36, 123, 255, 0.15);
		border-radius: 10rpx;
		padding: 0 40rpx 40rpx;
		box-sizing: border-box;
		overflow: hidden;

		.login_name {
			font-size: 40rpx;
			color: #333333;
			margin: 40rpx 0 10rpx;
		}

		.login_input {
			height: 95rpx;
			border-bottom: 2rpx solid #eee;
			line-height: 95rpx;
			display: flex;
			align-items: center;

			image {
				width: 35rpx;
			}

			input {
				margin-left: 25rpx;
				height: 95rpx;
				flex: 1;
				font-size: 26rpx;
				color: black;
			}
		}

		.login_btn {
			width: 540rpx;
			height: 80rpx;
			text-align: center;
			line-height: 80rpx;
			background: #247BFF;
			border-radius: 40rpx;
			font-size: 30rpx;
			color: #FFFFFF;
			margin-top: 40rpx;
		}

		.code-img {
			position: absolute;
			width: 150rpx !important;
			right: 40rpx;
		}
	}
</style>
